package telasDeCadastros;


import Geral.Menu;
import entidade.Aluno;
import java.sql.Date;

/**
 *
 * @author
 * Thomas Magnno Martins
 * Alexandre Junior Martins
 * Wanderson Ferreira Barboza
 */
public class CadastroAluno extends javax.swing.JFrame {

    /** Creates new form CadastroAluno */
    public CadastroAluno() {
        initComponents();
    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Sexo = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        txtEscolaridade = new javax.swing.JTextField();
        txtNaturalidade = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtProfissao = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtMatricula = new javax.swing.JTextField();
        txtNome = new javax.swing.JTextField();
        txtDataNascimento = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtNacionalidade = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        rdMasc = new javax.swing.JRadioButton();
        rdFem = new javax.swing.JRadioButton();
        cbEstadoCivil = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        txtNomePai = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtNomeMae = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jbanner = new javax.swing.JLabel();
        btnSair = new javax.swing.JButton();
        lblMensagem = new javax.swing.JLabel();
        btnAvançar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setForeground(java.awt.Color.white);
        setMaximizedBounds(new java.awt.Rectangle(0, 0, 706, 740));
        setMinimumSize(new java.awt.Dimension(705, 738));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 16));
        jLabel1.setForeground(new java.awt.Color(0, 102, 204));
        jLabel1.setText("Cadastro de Aluno");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 2, true), "Identificação Pessoa", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 11), new java.awt.Color(0, 102, 204))); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel1.add(txtEscolaridade, new org.netbeans.lib.awtextra.AbsoluteConstraints(398, 155, 234, -1));
        jPanel1.add(txtNaturalidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(398, 124, 234, -1));

        jLabel14.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel14.setText("Escolaridade : ");
        jPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(315, 158, -1, -1));
        jPanel1.add(txtProfissao, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 155, 145, -1));

        jLabel13.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel13.setText("Profissão : ");
        jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(94, 158, -1, -1));
        jPanel1.add(txtMatricula, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 31, 149, -1));
        jPanel1.add(txtNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 62, 472, -1));
        jPanel1.add(txtDataNascimento, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 93, 145, -1));

        jLabel2.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel2.setText("Matricula : ");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(97, 34, -1, -1));

        jLabel6.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel6.setText("Nacionalidade : ");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(72, 127, -1, -1));

        jLabel5.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel5.setText("Sexo : ");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(358, 96, -1, -1));
        jPanel1.add(txtNacionalidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 124, 145, -1));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel4.setText("Data de Nascimento :");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(42, 96, -1, -1));

        jLabel3.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel3.setText("Nome : ");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(115, 65, -1, -1));

        jLabel8.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel8.setText("Estado Civil : ");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(361, 34, -1, -1));

        jLabel7.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel7.setText("Naturalidade : ");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(317, 127, -1, -1));

        Sexo.add(rdMasc);
        rdMasc.setText("Masculino");
        jPanel1.add(rdMasc, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 90, -1, -1));

        Sexo.add(rdFem);
        rdFem.setText("Feminino");
        rdFem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdFemActionPerformed(evt);
            }
        });
        jPanel1.add(rdFem, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 90, -1, -1));

        cbEstadoCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "Solteiro(a)", "Casado(a)", "Divorciado(a)", "Separado(a)", "Viuvo(a)", "Amasiado(a)" }));
        jPanel1.add(cbEstadoCivil, new org.netbeans.lib.awtextra.AbsoluteConstraints(437, 31, 195, 20));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 2, true), "Filiação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 11), new java.awt.Color(0, 102, 204))); // NOI18N
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel2.add(txtNomePai, new org.netbeans.lib.awtextra.AbsoluteConstraints(155, 31, 477, -1));

        jLabel10.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel10.setText("Nome Mãe :");
        jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(87, 65, -1, -1));
        jPanel2.add(txtNomeMae, new org.netbeans.lib.awtextra.AbsoluteConstraints(155, 62, 477, -1));

        jLabel9.setFont(new java.awt.Font("Arial", 1, 11));
        jLabel9.setText("Nome Pai : ");
        jPanel2.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(87, 34, -1, -1));

        jbanner.setIcon(new javax.swing.ImageIcon(getClass().getResource("/telasDeCadastros/banner.jpg"))); // NOI18N
        jbanner.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 2, true));

        btnSair.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnSair.setText("Sair");
        btnSair.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 2, true));
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });

        lblMensagem.setForeground(new java.awt.Color(255, 0, 51));

        btnAvançar.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnAvançar.setText("Avançar");
        btnAvançar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 2, true));
        btnAvançar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAvançarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(268, 268, 268)
                .addComponent(jLabel1)
                .addGap(312, 312, 312))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnAvançar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSair, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE)))
                .addContainerGap(27, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(lblMensagem, javax.swing.GroupLayout.DEFAULT_SIZE, 702, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addComponent(jbanner, javax.swing.GroupLayout.DEFAULT_SIZE, 712, Short.MAX_VALUE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnAvançar, btnSair});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jbanner, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblMensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSair, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAvançar, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(185, 185, 185))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnAvançar, btnSair});

        setBounds(150, 0, 718, 774);
    }// </editor-fold>//GEN-END:initComponents

    private void btnAvançarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAvançarActionPerformed

        Aluno aluno = new Aluno();

        Date dataNasc = null;
        boolean dataValida = false;

        try {
            String[] vData = txtDataNascimento.getText().split("/");
            dataNasc = new Date(Integer.parseInt(vData[2]), Integer.parseInt(vData[1])-1, Integer.parseInt(vData[0]));
            dataValida = true;

        } catch (Exception e) {
            e.printStackTrace();
        }

         if(txtMatricula.getText().trim().equals("")){
            lblMensagem.setText("O campo matricula é obrigatório!");

        }else if(txtNome.getText().trim().equals("")){
            lblMensagem.setText("O campo nome é obrigatórios!");

        }else if(txtDataNascimento.getText().trim().equals("")){
            lblMensagem.setText("O campo data de nascimento é obrigatórios!");
            
        } else if (! dataValida) {
            lblMensagem.setText("Data informada com formato inválido!");

       
      
        }else{

         //Bloco Identificação Pessoa
        aluno.matricula = txtMatricula.getText().trim().toUpperCase();
        aluno.nome = txtNome.getText().trim().toUpperCase();
        aluno.setDtnasc(dataNasc);
        aluno.nacionalidade = txtNacionalidade.getText().trim().toUpperCase();
        aluno.naturalidade = txtNaturalidade.getText().trim().toUpperCase();
        aluno.profissao = txtProfissao.getText().trim().toUpperCase();
        aluno.grauesc = txtEscolaridade.getText().trim().toUpperCase();
        String estadoCivil = (String) cbEstadoCivil.getSelectedItem();
        aluno.estadocivil = estadoCivil;


        //Bloco Filiação
        aluno.nomepai = txtNomePai.getText().trim().toUpperCase();
        aluno.nomemae = txtNomeMae.getText().trim().toUpperCase();

        if(rdMasc.isSelected()) {
            aluno.sexo = "M";

        }else if(rdFem.isSelected()){
             aluno.sexo = "F";}

        CadastroAluno2 cadastro = new CadastroAluno2();
        cadastro.inicializar(aluno);
        this.dispose();

        }

    }//GEN-LAST:event_btnAvançarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
       this.dispose();
       Menu menu = new Menu();
       menu.setVisible(true);
    }//GEN-LAST:event_btnSairActionPerformed

    private void rdFemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdFemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rdFemActionPerformed
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CadastroAluno().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup Sexo;
    private javax.swing.JButton btnAvançar;
    private javax.swing.JButton btnSair;
    private javax.swing.JComboBox cbEstadoCivil;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel jbanner;
    private javax.swing.JLabel lblMensagem;
    private javax.swing.JRadioButton rdFem;
    private javax.swing.JRadioButton rdMasc;
    private javax.swing.JTextField txtDataNascimento;
    private javax.swing.JTextField txtEscolaridade;
    private javax.swing.JTextField txtMatricula;
    private javax.swing.JTextField txtNacionalidade;
    private javax.swing.JTextField txtNaturalidade;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtNomeMae;
    private javax.swing.JTextField txtNomePai;
    private javax.swing.JTextField txtProfissao;
    // End of variables declaration//GEN-END:variables

}
